package GUI;

import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import Client.BusinessImplements;
import Controler.Update_Book_Details_controler;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.border.LineBorder;
/**
 @author Lucie
 * Class name  Update_Details_Book_Select_Book
 * extend  Abstract_Jpanel
 * purpose: select item id that the user like to update
 */
public class Update_Details_Book_Select_Book extends Abstract_Jpanel {
	private JTextField textFieldid;
	public JButton btnGo;
	private JPanel panel;
	private JLabel lblChoseItem;
	private Update_Book_Details_controler up_book_deatails;
	private JButton btnBack;
	private JLabel lblChoose;
	/**
	 * Create the panel.
	 */
	public Update_Details_Book_Select_Book() {
		setLayout(null);
		
		panel = new JPanel();
		panel.setBorder(new LineBorder(SystemColor.activeCaption, 6));
		panel.setBackground(SystemColor.inactiveCaption);
		panel.setBounds(21, 59, 478, 200);
		add(panel);
		panel.setLayout(null);
		
		textFieldid = new JTextField();
		textFieldid.setBounds(148, 45, 172, 20);
		panel.add(textFieldid);
		textFieldid.setColumns(10);
		
		JLabel lblBookId = new JLabel("Book Id:");
		lblBookId.setBounds(56, 42, 72, 23);
		panel.add(lblBookId);
		lblBookId.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		lblChoose = new JLabel("choose an item to update his detaeles");
		lblChoose.setForeground(Color.RED);
		lblChoose.setFont(new Font("Segoe Print", Font.PLAIN, 13));
		lblChoose.setBounds(55, 86, 278, 23);
		panel.add(lblChoose);
		 
		 lblChoseItem = new JLabel("Choose an Item");
		 lblChoseItem.setForeground(new Color(25, 25, 112));
		 lblChoseItem.setFont(new Font("MV Boli", Font.BOLD, 30));
		 lblChoseItem.setBounds(41, 11, 335, 39);
		 add(lblChoseItem);
		 /*
		  * btnBack goes back to sing in panel
		  */
		 btnBack = new JButton("back");
		 btnBack.addActionListener(new ActionListener() {
		 	public void actionPerformed(ActionEvent e) {
		 		Sign_in_panel sip=new Sign_in_panel();
				on_screen_unload();
				BusinessImplements.GetInstance().getMainFrame().setContentPane(sip);
				sip.setSize(getMaximumSize());
				sip.on_screen_load();
		 		
		 	}
		 });
		 btnBack.setFont(new Font("Tahoma", Font.PLAIN, 14));
		 btnBack.setBounds(31, 270, 83, 39);
		 add(btnBack);
		 /*
		  * goes to Update_Deatails_Book 
		  */
		  btnGo = new JButton("Go");
		  btnGo.setBounds(407, 270, 83, 39);
		  add(btnGo);
		  btnGo.setFont(new Font("Tahoma", Font.PLAIN, 14));
		 btnGo.addActionListener(new ActionListener() {
		 	public void actionPerformed(ActionEvent e) {
		 		
		 		 up_book_deatails=new Update_Book_Details_controler();
		 		ArrayList<String> item_deatails=up_book_deatails.get_item(get_book_id());
				
		 		if (!(item_deatails==null))
		 		{
		 		Managment_panel mangment_panel=new Managment_panel();
		   		on_screen_unload();
		   		BusinessImplements.GetInstance().getMainFrame().setContentPane(mangment_panel.update_book_deatails);
		 		mangment_panel.update_book_deatails.setSize(getMaximumSize());
		 		mangment_panel.update_book_deatails.on_screen_load(item_deatails);
		 		}
		 		else
		 		{
		 			next_screen_faild( up_book_deatails.get_msg());
		 		}
		 			
		 			
		 	}
		 });

	}
	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void on_screen_load() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void on_screen_unload() {
		// TODO Auto-generated method stub
		
	}
	/**
	 * 
	 * @return book id
	 */
	public String get_book_id()
	{
		return textFieldid.getText();
	}
	/**
	 * this method display showMessageDialog with a failed msg
	 * @param msg
	 */
	public void next_screen_faild(String msg)
	{
		JOptionPane.showMessageDialog(this,"apply faild "+msg);
	}
	

}
